home *** CD-ROM | disk | FTP | other *** search
- /****i* SOURCE_FILE/INFO
- *
- * NAME
- * HexUtils.js
- *
- * USAGE
- * Part of WSP JavaScript Library.
- *
- * COPYRIGHT
- * Copyright ⌐ 2000-2005 Website Pros, Inc.
- * All Rights Reserved.
- *
- * This is an unpublished work protected by Website Pros, Inc.
- * as a trade secret, and is not to be used or disclosed except as
- * expressly provided in a written license agreement executed by
- * you and Website Pros, Inc.
- *
- * <copyright@websitepros.com>
- *
- * NOTES
- * JavaScript code.
- *
- *****/
-
- if (!IS.isModuleInitialized("IS.NOF.UTIL.HexUtils"))
- {
- /****h* NOF_JavaScript_Library/NOF.UTIL.HexUtils
- *
- * NAME
- * NOF.UTIL.HexUtils
- *
- * DESCRIPTION
- *
- * The <code>HexUtils</code> class contains code to convert hex into other format and viceversa
- *
- ****/
- function UTIL_HexUtils() {
- this.__proto__ = UTIL_HexUtils.prototype;
- }
- {
- var method = UTIL_HexUtils.prototype;
-
- /**
- * Convert number from hexa to decimal format
- * @param hexa - the number to be converted
- ***/
- method.hexToDec = function (/*string*/ hexa) {
- var temp = parseInt(hexa, 16);
- return temp;
- }
-
- /**
- * Convert number from decimal to hexa format
- * @param decimal - the number to be converted
- ***/
- method.decToHex = function (/*string*/ decimal) {
- var temp = parseInt(decimal,10);
-
- if (isNaN(temp)) {
- return null;
- }
-
- var hex = "";
- while (temp > 15) {
- var remainder = temp % 16;
- hex = this.getHexDigit(remainder) + "" + hex;
- temp = parseInt(temp / 16);
- }
- if (temp >= 0) {
- hex = this.getHexDigit(temp) + "" + hex;
- }
- else {
- return 0;
- }
-
- var size = hex.length;
- var zeros = "";
- if ( size != 6 ) {
- for (var j=0; j < 6 - size; j++ ) {
- zeros = zeros + "0";
- }
- }
- return zeros + hex;
- }
-
- // private method
- method.getHexDigit = function (/*string*/ decimal) {
- var hexArray = Array("A", "B", "C", "D", "E", "F");
- var hexVal = parseInt(0 + decimal, 10);
-
- if ((hexVal) > 15) {
- return null;
- }
- else {
- hexVal = hexVal < 10 ? hexVal : hexArray[hexVal-10];
- }
- return hexVal;
- }
- }
-
- UTIL.__proto__.HexUtils = new UTIL_HexUtils();
- }